﻿
@{
    ViewBag.Title = "MemConsumGridlView";
        Layout = null;
}



<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="~/layui/css/layui.css" />
    <script src="~/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/layui/jquery-3.4.1.js"></script>

    <title>会员消费情况统计</title>
    <style type="text/css">
        .layui-input {
            margin-top: 5px;
            height: 30px
        }

        .layui-form-label {
            width: auto;
            padding: 5px 10px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <fieldset class="layui-elem-field layui-field-title">
        <legend>
            查询
        </legend>
    </fieldset>
    <div>

        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">消费日期</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="start_time" lay-verify="Begintiem" name="start_time">
                </div>
                <label class="layui-form-label">至</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="end_time" lay-verify="Endtiem" name="start_time">
                </div>
                @*<label class="layui-form-label">至</label>
                <div class="layui-inline">
                    <input type="text" class="layui-input" id="end_time" lay-verify="Endtiem" name="start_time">
                </div>*@

                <label class="layui-form-label">卡号/手机</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="MC_CardID">
                </div>

                <label class="layui-form-label">消费类型:</label>
                <div class="layui-input-inline">
                    @Html.DropDownList("CO_OrderType", ViewBag.CardLevelId as IEnumerable<SelectListItem>, "")


                </div>

                <button id="searh" type="button" class="layui-btn layui-btn layui-btn-sm" style="margin-top: 5px;"><i class="layui-icon">&#xe615;搜索</i></button>
            </div>
        </form>
            </div>

       


    <fieldset class="layui-elem-field layui-field-title">
    </fieldset>
    <table class="layui-inline" lay-filter="memList" id="memList"></table>
    <table class="layui-inline" lay-filter="cardList" id="cardList"></table>




    <script>

        layui.use(['table', 'layer', 'laydate'], function () {
            var table = layui.table,
                layer = layui.layer;
            laydate = layui.laydate;
            var endDate = laydate.render({
                elem: '#end_time',//选择器结束时间
                type: 'datetime',
                min: "1970-1-1",//设置min默认最小值
                trigger: 'click',//指定元素
                done: function (value, date) {
                    startDate.config.max = {
                        year: date.year,
                        month: date.month - 1,//关键
                        date: date.date
                    }
                }
            });
            //日期范围
            var startDate = laydate.render({
                elem: '#start_time',
                type: 'datetime',
                max: "2099-12-31",//设置一个默认最大值
                trigger: 'click',//指定元素
                done: function (value, date) {
                    endDate.config.min = {
                        year: date.year,
                        month: date.month - 1, //关键
                        date: date.date,

                    };
                }
            });
            $('#searh').on('click', function () {
                //获取输入框的值
                var MC_CardID = $('#MC_CardID').val();
                var EndTime = $('#end_time').val();
                var StartTime = $('#start_time').val();
                if (MC_CardID.length > 6) {
                    var reg = /^[1]([3-9])[0-9]{9}$/;
                    if (!reg.test(MC_CardID)) {
                        alert("请输入正确的手机号")
                        return false;
                    }
                }
                if (EndTime == "" && StartTime != "") {
                    alert("请选择结束日期")
                    return false;
                }
                if (StartTime == "" && EndTime != "") {
                    alert("请选择开始日期")
                    return false;
                }
                var CO_OrderCode = $("#CO_OrderCode").val();
                var CL_ID = $("#CL_ID").val();
                var Minus = $("#Minus").val();
                var CO_OrderType = $("#CO_OrderType").val();
                //表格重载，并传回服务器参数
                table.reload('cardList', {
                    //提交方式 Post
                    method: 'post',
                    //传回服务器的参数
                    where: {
                        'MC_CardID': MC_CardID,
                        'StartTime': StartTime,
                        'EndTime': EndTime,
                        'CO_OrderCode': CO_OrderCode,
                        'CL_ID': CL_ID,
                        'Minus': Minus,
                        'CO_OrderType': CO_OrderType
                    }
                });
            })

            //单击行
            table.on('row(memList)', function(obj){
                console.log(obj.tr) //得到当前行元素对象
               var MC_CardID= obj.data.MC_CardID //得到当前行数据
                        //表格重载，并传回服务器参数
                table.reload('cardList', {
                    //提交方式 Post
                    method: 'post',
                    //传回服务器的参数
                    where: {
                        MC_CardID: MC_CardID,
                      
                    }
                });

                });



             table.render({
                elem: '#memList',
                url: '/CountSum/GetMemConsumGridlView',
                //开启分页
                page: 'true',
                cols: [
                    [
                    {
                        field: 'MC_CardID',
                        width: 150,
                        title: '会员卡号',
                        sort: true
                    },
                    {
                        field: 'MC_Name',
                        width: 150,
                        title: '会员姓名',
                        sort: true
                    },
                    {
                        field: 'MC_TotalMoney',
                        width: 150,
                        title: '累计消费',
                        sort: true
                    }

                   
                    ]
                ]
            });

            //载入表格
            table.render({
                elem: '#cardList',
                url: '/CountSum/GetMemConsumGridlView',
                //开启分页
                page: 'true',
                cols: [
                    [{
                        field: 'CO_OrderCode',
                        width: 150,
                        title: '订单编号',
                        sort: true
                    },
                    {
                        field: 'MC_CardID',
                        width: 150,
                        title: '会员卡号',
                        sort: true
                    },
                    {
                        field: 'MC_Name',
                        width: 150,
                        title: '会员姓名',
                        sort: true
                    },
                    {
                        field: 'CO_DiscountMoney',
                        width: 150,
                        title: '消费金额',
                        sort: true
                    },

                    {
                        field: 'CO_GavePoint',
                        width: 150,
                        title: '获得积分',
                        sort: true,
                    },
                    {
                        field: 'CO_CreateTime',
                        width: 150,
                        title: '消费时间',
                        sort: true,
                        templet: function (d) {
                            return FormatToDate(d.CO_CreateTime)
                        }
                    },
                    {
                        field: '',
                        width: 150,
                        title: '支付方式',
                        sort: true,
                        },
                          {
                        field: 'CO_OrderType',
                        width: 150,
                        title: '类型',
                        sort: true,
                    }
                    ]
                ]
            });
        })

        //转换日期方法
        function FormatToDate(val) {
            if (val != null) {
                var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
                //月份为0-11，所以+1，月份小于10时补个0
                var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                return date.getFullYear() + "-" + month + "-" + currentDate;
            }
            return "";
        }


    </script>
</body>
</html>










